package edu.cuc.nio.buffer;

import java.nio.IntBuffer;

/**
 * 自缓冲区
 */
public class BufferDemo02 {
    public static void main(String[] args) {
        IntBuffer buf = IntBuffer.allocate(10);
        IntBuffer sub = null;
        for(int i = 0;i<10;i++) {
            buf.put(i * 2 + 1);
        }
        buf.position(2);
        buf.limit(6);
        sub = buf.slice();

        for (int i = 0 ;i<sub.capacity();i++) {
            int temp = sub.get(i);
            sub.put(temp - 1);
        }
        buf.flip();
        buf.limit(buf.capacity());
        while (buf.hasRemaining()) {
            System.out.println(buf.get());
        }
    }
}
